package job.work.service.system.service.impl;

import job.work.domain.response.CommonCode;
import job.work.domain.response.ResponseResult;
import job.work.domain.system.entity.pojo.dto.SignLoginUser;
import job.work.domain.system.entity.pojo.model.SystemUser;
import job.work.service.auth.AuthService;
import job.work.service.system.service.SystemService;
import job.work.service.system.service.UserService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * 普通用户
 *
 * @author Administrator
 */
@Service
public class UserServiceImpl implements UserService {


    @Resource
    SystemService systemService;


    @Resource
    AuthService authService;

    /**
     * 根据用户ID更新用户钱包
     *
     * @param id     用户Id
     * @param wallet 用户钱包
     */
    @Override
    public ResponseResult saveWallet(Long id, BigDecimal wallet) {
        systemService.saveWallet(id, wallet);
        return ResponseResult.SUCCESS();
    }

    /**
     * 注册用户
     * @param signLoginUser 用户信息
     * @return
     */
    @Override
    public ResponseResult signInUser(SignLoginUser signLoginUser){
       String mobile = signLoginUser.getMobile();
        SystemUser systemMobile = systemService.findSystemMobile(mobile);
        if (systemMobile != null){

            return  new ResponseResult(CommonCode.FAIL,"该手机号已被注册!");
        }
        //验证验证码
        authService.validateVie(mobile,signLoginUser.getVerifycode());
        //保存新注册的用户
        SystemUser systemUser = new SystemUser();
        systemUser.setUsername(mobile);
        systemUser.setPhone(mobile);
        systemUser.setRoleId(0L);
        SystemUser save = systemService.save(systemUser);
        return  new ResponseResult(CommonCode.SUCCESS,"恭喜你注册成功!");

    }

    /**
     * 删除用户信息
     *
     * @param id 用户ID SYSID
     * @return 操作结果
     */
    @Override
    public ResponseResult deleteSysUser(Long id) {
        //TODO  删除微信用户信息表和QQ信息表
        return systemService.deleteById(id);
    }


}
